package IC.Parser;

%%


%class Lexer
%public
%function next_token
%type Token
%line
%scanerror LexicalError

%state STRING
%state COMMENTS
%state COMMENTS2
%state QUOTEDSTRING
%state SEENCLASS
%state CLASSIDENTIFIER



ALPHA=[A-Za-z_] 
DIGIT=[0-9]
ALPHA_NUMERIC={ALPHA}|{DIGIT}
IDENT={ALPHA}({ALPHA_NUMERIC})*
NUMBER=({DIGIT})+



%%

//A rule for comments
<YYINITIAL> "//" { yybegin(COMMENTS); }
<COMMENTS> [^\n] { }
<COMMENTS> [\n] { yybegin(YYINITIAL); }

//A rule for comments2
<YYINITIAL> "/*" { yybegin(COMMENTS2); }
<COMMENTS> [^"*/"] { }
<COMMENTS> ["*/"] { yybegin(YYINITIAL); }

//A rule for string
<YYINITIAL> "\"" {yybegin(QUOTEDSTRING);}
<QUOTEDSTRING> [^\"] {}
<QUOTEDSTRING> [\"] {return new Token (sym.QUOTE,yyline,yytext());}





"(" 				{return new Token (sym.LP,yyline); }
")" 				{return new Token (sym.RP,yyline); }
"=" 				{return new Token (sym.ASSIGN,yyline);}
"boolean"			{return new Token (sym.BOOLEAN,yyline); }
"break"				{return new Token (sym.BREAK,yyline);}

"class" 			{
//How do we get the Class Identifier? 
return new Token (sym.CLASS,yyline);}




"," 				{return new Token (sym.COMMA,yyline);}
"continue"			{return new Token (sym.CONTINUE,yyline);}
"/"					{return new Token (sym.DIVIDE,yyline);}
"."					{return new Token (sym.DOT,yyline);}
"=="				{return new Token (sym.EQUAL,yyline);}
"extends"			{return new Token (sym.EXTENDS,yyline);}
"else"				{return new Token (sym.ELSE,yyline);}
"false"				{return new Token (sym.FALSE,yyline);}
">"					{return new Token (sym.GT,yyline);}
">="				{return new Token (sym.GTE,yyline);}
"identifier"		{return new Token (sym.ID,yyline);}
"if"				{return new Token (sym.IF,yyline);}
"int"				{return new Token (sym.INT,yyline);}
"integer"			{return new Token (sym.INTEGER,yyline);}
"&&"				{return new Token (sym.LAND,yyline);}
"["					{return new Token (sym.LB,yyline);}
"{"					{return new Token (sym.LCBR,yyline);}
"length"			{return new Token (sym.LENGTH,yyline);}
"new"				{return new Token (sym.NEW,yyline);}
"!"					{return new Token (sym.LNEG,yyline);}
"||"				{return new Token (sym.LOR,yyline);}
"<"					{return new Token (sym.LT,yyline);}
"<="				{return new Token (sym.LTE,yyline);}
"-"					{return new Token (sym.MINUS,yyline);}
"%"					{return new Token (sym.MOD,yyline);}
"*"					{return new Token (sym.MULTIPLY,yyline);}
"!="				{return new Token (sym.NEQUAL,yyline);}
"null"				{return new Token (sym.NULL,yyline);}
"+"					{return new Token (sym.PLUS,yyline);}
"]"					{return new Token (sym.RB,yyline);}
"}"					{return new Token (sym.RCBR,yyline);}
"return"			{return new Token (sym.RETURN,yyline);}
";"					{return new Token (sym.SEMI,yyline);}
"static"			{return new Token (sym.STATIC,yyline);}
"string"			{return new Token (sym.STRING,yyline);}
"this"				{return new Token (sym.THIS,yyline);}
"true"				{return new Token (sym.TRUE,yyline);}
"void"				{return new Token (sym.VOID,yyline);}
"while"				{return new Token (sym.WHILE,yyline);}

IDENT 				{return new Token (sym.ID,yyline);}
//Should we discard numbers ? 
NUMBER				{}
